/*
 This file is part of BTStracker
		
    BTStracker is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    BTStracker is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.	
	author: azbest.pro (azbest.pro@gmail.com)
*/
package pl.vdl.azbest.mremote.com;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Logger;

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import pl.vdl.azbest.log.LoggingTheGathering;
import pl.vdl.azbest.mremote.Conf;

class CSDisconnected implements CState {
	private CConnect conn;
	private Logger logger = Logger.getLogger(getClass().getName());
	{
		LoggingTheGathering.addPath(getClass().getName());
	}
	public CSDisconnected(CConnect conn) {
		this.conn = conn;
	}

	public void connect() {
		logger.info("You are still disconnected - performing tests");
		CommPortIdentifier port = Conf.getInstance().getDevicePort();
		int rate = Conf.getInstance().getDeviceBaudRate();
		boolean inUse = port.isCurrentlyOwned();

		if (inUse) {
			conn.setState(CommState.CONNECTION_FAILURE, "Port is in use.");
			return;
		}
		logger.info("Performing connection - port in use test passed.");
		logger.info("Performing connection - setting to CONNECTING state and perorming act.");
		conn.setState(CommState.CONNECTING, "Connecting to device "
				+ port.getName() + "...", conn.sConnecting);
		conn.perform();
	}

	public void disconnect() {
		// TODO Auto-generated method stub

	}

	public void error() {
		// TODO Auto-generated method stub

	}
	public void perform(){}

	public void timeout() {
		// TODO Auto-generated method stub

	}

	public void openCommunication() {
		// TODO Auto-generated method stub

	}

	public void closeCommunication() {
	}
	public void write(String line ) {
		// TODO Auto-generated method stub

	}

}
